/**
 * @file categories/dp/dp_on_tree/spoj_mtele/main.cpp
 * @brief
 * @see
 * @author Ruiming Guo (guoruiming@stu.scu.edu.cn)
 * @copyright 2022
 * @date 2022/7/4 11:18:41
 **/

// TODO: TLE

#include <bits/stdc++.h>
using namespace std;
const int N = 3010;
const int inf = (1 << 29);
int n, m;
vector<int> adj[N], cost[N];
int ar[N];
int dp[N][N];
int temp[N];

int dfs(int u) {
  dp[u][0] = 0;
  if (u >= n - m) {
    dp[u][1] = ar[u];
    return 1;
  }
  int mx = 0;
  for (int i = 0; i < adj[u].size(); ++i) {
    int x = dfs(adj[u][i]);
    mx += x;
    for (int j = 0; j <= mx; ++j) temp[j] = -inf;
    for (int j = 0; j <= mx; ++j) {
      for (int k = 0; k <= j; ++k) {
        int cur = dp[adj[u][i]][k] - cost[u][i];
        temp[j] = max({temp[j], dp[u][j], dp[u][j - k] + cur});
      }
    }
    for (int j = 0; j <= mx; ++j) {
      dp[u][j] = max(dp[u][j], temp[j]);
    }
  }
  return mx;
}
int main() {
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < N; ++j) dp[i][j] = -inf;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    int k;
    scanf("%d", &k);
    while (k--) {
      int v, l;
      scanf("%d%d", &v, &l);
      v--;
      adj[i].push_back(v);
      cost[i].push_back(l);
    }
  }
  for (int i = n - m; i < n; ++i) {
    int l;
    scanf("%d", &l);
    ar[i] = l;
  }
  dfs(0);
  int ans = n;
  while (dp[0][ans] < 0) ans--;
  printf("%d\n", ans);
}
